package com.android.myapplication.third.greendao;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.NotNull;
import org.greenrobot.greendao.annotation.Property;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.List;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;
import com.greendao.gen.DaoSession;
import com.greendao.gen.StudentBean2Dao;
import com.greendao.gen.TeacherBeanDao;

@Entity(nameInDb="teacher")
public class TeacherBean {
    @Id
    Long id;

    @Property
    @NotNull
    String name;

    @Property
    Integer sex;

    @Property(nameInDb = "year")
    Integer age;


    @Property
    String className;


    @ToMany(referencedJoinProperty = "fk_teacher_id")
    List<StudentBean2> studentList;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 121856788)
    private transient TeacherBeanDao myDao;


    @Generated(hash = 699411423)
    public TeacherBean(Long id, @NotNull String name, Integer sex, Integer age,
            String className) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.className = className;
    }


    @Generated(hash = 1376380279)
    public TeacherBean() {
    }


    public Long getId() {
        return this.id;
    }


    public void setId(Long id) {
        this.id = id;
    }


    public String getName() {
        return this.name;
    }


    public void setName(String name) {
        this.name = name;
    }


    public Integer getSex() {
        return this.sex;
    }


    public void setSex(Integer sex) {
        this.sex = sex;
    }


    public Integer getAge() {
        return this.age;
    }


    public void setAge(Integer age) {
        this.age = age;
    }


    public String getClassName() {
        return this.className;
    }


    public void setClassName(String className) {
        this.className = className;
    }


    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 2047248363)
    public List<StudentBean2> getStudentList() {
        if (studentList == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            StudentBean2Dao targetDao = daoSession.getStudentBean2Dao();
            List<StudentBean2> studentListNew = targetDao
                    ._queryTeacherBean_StudentList(id);
            synchronized (this) {
                if (studentList == null) {
                    studentList = studentListNew;
                }
            }
        }
        return studentList;
    }


    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1628625923)
    public synchronized void resetStudentList() {
        studentList = null;
    }


    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }


    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }


    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }


    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 1588249045)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getTeacherBeanDao() : null;
    }

    public String toString(){
        List<StudentBean2> studentList = getStudentList();
        StringBuffer buffer = new StringBuffer();
        if (studentList != null && studentList.size() > 0){
            buffer.append(";  学生:");

            for (StudentBean2 studentBean2 : studentList){
                buffer.append(studentBean2.getName()).append(",");
            }
        }
        return "教师名称: "+name + buffer.toString();
    }
}
